#!/bin/sh

#%Module
#% description: To establish and control use of a graphics display monitor.
#% keywords: display
#%End
#%Flag
#% key: l
#% description: List all monitors
#%End
#%Flag
#% key: L
#% description: List all monitors (with current status)
#%End
#%Flag
#% key: p
#% description: Print name of currently selected monitor
#%End
#%Flag
#% key: r
#% description: Release currently selected monitor
#%End
#%Flag
#% key: s
#% description: Do not automatically select when starting
#%End
#%Option
#% key: start
#% type: string
#% required: no
#% multiple: no
#% description: Name of graphics monitor to start (p0-p9)
#%End
#%Option
#% key: stop
#% type: string
#% required: no
#% multiple: no
#% description: Name of graphics monitor to stop
#%End
#%Option
#% key: select
#% type: string
#% required: no
#% multiple: no
#% description: Name of graphics monitor to select
#%End
#%Option
#% key: unlock
#% type: string
#% required: no
#% multiple: no
#% description: Name of graphics monitor to unlock
#%End

if [ -z "$GISBASE" ] ; then
    echo "You must be in GRASS GIS to run this program." 1>&2
    exit 1
fi

if [ "$1" != "@ARGS_PARSED@" ] ; then
    exec g.parser "$0" "$@"
fi

# CODE GOES HERE

PYTHONPATH="$GISBASE/etc/wx"

export PYTHONPATH

start="$GIS_OPT_START"
select="$GIS_OPT_SELECT"
stop="$GIS_OPT_STOP"
unlock="$GIS_OPT_UNLOCK"

# create the command file
command_file="`g.tempfile pid=$$`"
g.gisenv set=GRASS_PYCMDFILE=${command_file}

if [ -n "$start" ] ; then
    python $PYTHONPATH/gui_modules/mapdisp.py "$start" ${command_file} &
fi

if [[ -n "$stop" || -n "$select" || -n "$unlock" ]] ; then
    g.message -w "Not implemented yet"
fi

exit 0
